package com.rui.admin.controller;

import com.rui.admin.mapper.StarMapper;
import com.rui.common.pojo.Star;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class StarController {
    @Resource
    StarMapper starMapper;

    @GetMapping("/addStar")
    public String addStar(int star,int sid){
        System.out.println(star);
        try {
            Integer row = starMapper.addStar(star,sid);
            if(row>0){
                return "success";
            }
            return "fail";
        }catch (Exception e){
            return "fail";
        }

    }

    @GetMapping("/findStar")
    public int findStar(int sid){
        List<Star> star = starMapper.findStar(sid);
        int mstart = 0;
        int len = 0;
        for(Star star1:star){
            mstart+=star1.getStar();
            len++;
        }
        if(len==0){
            return 0;
        }
        return mstart/len;

    }
}
